home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-05
/
scnsrv.zip
/
SCANSERV.C
< prev
next >
Wrap
Text File
|
1992-10-23
|
5KB
|
272 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <conio.h>
#include <dir.h>
#include <share.h>
#include <errno.h>
#include <sys\stat.h>
#include <dos.h>
#include "version.h"
#pragma hdrstop
#include "newnov.h"
#define DEBUG 0
// --------------------------------------------------------------------------
// main()
//
// --------------------------------------------------------------------------
struct NovellFileInfo nfi;
void
PrintDOSdate(unsigned long t, char *str)
{
struct ftime *ftp = (struct ftime *) &t;
#define ft (*ftp)
t =
LongSwap(t);
// printf("File time: %u:%u:%u ",
// ft.ft_hour, ft.ft_min,
// ft.ft_tsec * 2);
cprintf( "%s%02.2u-%02.2u-%04.4u", str,
ft.ft_month, ft.ft_day, ft.ft_year+1980);
}
int // J F M A M J J A S O N D
julian_table[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
int
julian(int year, int month, int day)
{
return (day-1 + julian_table[month-1] + (year-1980)*365 );
}
int
julianDOSdate(unsigned long t)
{
struct ftime *ftp = (struct ftime *) &t;
t =
LongSwap(t);
return julian(ft.ft_year+1980, ft.ft_month, ft.ft_day);
}
struct date today;
int today_julian;
int
scanit(char *path)
{
int seqnum, res;
int pathendindex;
struct ScanDirInfoReply *dip;
char *newpath;
// Allocate a new path with enough room for catting an 8.3 name
// and a backslash.
// then check mem allocation
pathendindex = strlen(path);
// protect against creating a volname:path string > 254 chars.
if (pathendindex > 254 - 14)
return 0;
// Construct new path and request structs
newpath = malloc(pathendindex + 14);
dip = malloc(sizeof(*dip));
if (!newpath || !dip) {
cprintf("Out of memory");
exit(1);
}
// announce the current dir, don't wrap the 80-column display!
putch('\r');
clreol();
if (pathendindex > (80-16))
cprintf("Scanning: ... %s", &(path[pathendindex-(80-16)]));
else
cprintf("Scanning: %s", path);
// create search path string for netware call
strcpy(newpath, path);
strcat(newpath, "\\*");
// scan all files in current directory
seqnum = -1;
while (1)
{
res = GetFileInfo(newpath, &nfi, seqnum);
seqnum = nfi.seqnum;
switch (res)
{
case 0:
printf("%lu\t%u\t%u\t%u\t%u\n",
LongSwap(nfi.fileSize),
today_julian - julianDOSdate(nfi.updateTime),
today_julian - julianDOSdate(nfi.archiveTime),
today_julian - julianDOSdate(nfi.creationDate),
today_julian - julianDOSdate(nfi.accessDate));
if (
today_julian - julianDOSdate(nfi.updateTime) < 0 ||
today_julian - julianDOSdate(nfi.archiveTime) < 0 ||
today_julian - julianDOSdate(nfi.creationDate) < 0 ||
today_julian - julianDOSdate(nfi.accessDate) < 0
)
{
putch('\r');
clreol();
cprintf("Date Anomaly on file: %s\\%s\r\n", path, nfi.filename);
PrintDOSdate(nfi.updateTime, "Update: ");
PrintDOSdate(nfi.archiveTime, " Archive: ");
PrintDOSdate(nfi.creationDate, " Create: ");
PrintDOSdate(nfi.accessDate, " Access: ");
cprintf("\r\n");
}
break;
case 0xFF: // no more files.
res = 0;
goto endloop;
default:
cprintf("Error %d during Get File Info on %s\n", res, path);
exit(1);
}
}
endloop:
// Done scanning files. Now scan for directories and recurse.
pathendindex++;
dip->subdirNumber = -1;
while (!res)
{
res = GetDirInfo(newpath, dip);
if (!res)
{
newpath[pathendindex] = '\0';
strcat(newpath, dip->filename);
scanit(newpath);
newpath[pathendindex] = '\0';
strcat(newpath, "*");
}
else
if (res != 0x9C)
{
cprintf("Error %d during Get Dir Info on %s\n", res, path);
exit(1);
}
else
{
res = 0;
break;
}
}
free(newpath); free(dip);
return (res == 0xff ? 0 : res);
}
int
scanServer(char *servername, int serverConnIndex)
{
char volName[20];
int volIndex;
int res = 0;
cprintf("\r\nScanning server %s\r\n", servername);
// Loop thru all volumes on a server, and scan them....
for (volIndex = 0; !res && (volIndex < 32); volIndex++)
{
if (!GetVolumeName(volName, volIndex))
{
strcat(volName, ":");
// Put out a marker to delineate a new volume scan
printf("---------------------- S%d V%d -------------------------\n",
serverConnIndex, volIndex);
// scan the volume.
res = scanit(volName);
}
}
return res;
}
int
main(int argc, char *argv[])
{
int res = 0;
int serverConnIndex = 0;
int saveConn;
char servername[50];
// Init julian date table and today's julian date.
{
int i;
for (i=1; i<12; i++)
julian_table[i] += julian_table[i-1];
}
getdate(&today);
today_julian = julian(today.da_year, today.da_mon, today.da_day);
// special option to allow a path to be spec'd on the command line
// for scanning...
if (argc > 1)
{
return scanit(argv[1]);
}
// Scan server table, when one is found, scan it.
while (!res && !GetNextServer(servername, &serverConnIndex))
{
saveConn = GetPreferredConnectionID();
SetPreferredConnectionID(serverConnIndex);
res = scanServer(servername, serverConnIndex);
SetPreferredConnectionID(saveConn);
}
return res;
}